package com.tanhua.model.db;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.tanhua.model.vo.ExtraVo;
import com.tanhua.model.vo.ReportUserVo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Report implements Serializable {
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;//报告id
    @TableField("userId")
    private Long userId;//用户id
    private String conclusion; //鉴定结果
    private String cover;//鉴定图片

    private String level;//问卷级别
    @TableField(exist = false)
    private Object[] dimensions;//维度
    @TableField(exist = false)
    private Object[] similarYou;//与你相似

    public static Report init(Report report, List<Extra> extra, UserInfo sUser) {
        List<ExtraVo> extraVos = new ArrayList<>();
        for (Extra extra1 : extra) {
            ExtraVo vo = new ExtraVo();
            vo.setKey(extra1.getKeyOne());
            vo.setValue(extra1.getValueOne());
            extraVos.add(vo);
        }
        report.setDimensions(extraVos.toArray());
        if (sUser != null) {
            List<ReportUserVo> rv = new ArrayList<>();
            ReportUserVo vo = new ReportUserVo();
            vo.setId(Integer.valueOf("" + sUser.getId()));
            vo.setAvatar(sUser.getAvatar());
            rv.add(vo);
            report.setSimilarYou(rv.toArray());
        }
        return report;
    }
}
